package conchmusic.conchmusicclient.util;

import android.util.Log;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import conchmusic.conchmusicclient.pojo.Song;
import conchmusic.conchmusicclient.pojo.SortMusic;

/**
 * Created by Administrator on 2017/5/2.
 */

public class SongGetScanMusic {
    private List<Song> date;
    private ArrayList<SortMusic> mSortList;
    private ArrayList<String> indexString;

    public SongGetScanMusic(List<Song> date) {
        this.date = date;
        filledData();
    }

    private void filledData() {
        mSortList = new ArrayList<>();
        indexString = new ArrayList<>();
        for (int i = 0; i < date.size(); i++) {
            SortMusic sortModel = new SortMusic();
            sortModel.setSong(date.get(i));
            String pinyin = PinyinUtils.getPingYin(date.get(i).getTitle());
            String sortString = pinyin.substring(0, 1).toUpperCase();
            if (sortString.matches("[A-Z]")) {
                sortModel.setSortLetters(sortString.toUpperCase());
                if (!indexString.contains(sortString)) {
                    indexString.add(sortString);
                }
            }else{
                sortModel.setSortLetters("#");
                if (!indexString.contains("#")) {
                    indexString.add("#");
                }
            }
            mSortList.add(sortModel);
        }
        Collections.sort(indexString);
    }

    public ArrayList<SortMusic> getmSortList() {
        return mSortList;
    }

    public ArrayList<String> getIndexString() {
        return indexString;
    }
}
